import { SPlayerOlympicGuessInfo } from "../../../../../Message/Game/SPlayerOlympicGuessInfo";
import { OlympicGuessAllData } from "./OlympicGuessAllData";
import { OlympicGuessData } from "./OlympicGuessData";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { EActiveType } from "../../../../../Message/Public/EActiveType";
import { ClockManager } from "../../../manager/ClockManager";
type int = number;
//class OlympicGuessDataParser
    
    export  class OlympicGuessDataParser
    {
        

        public parseData(arg1: SPlayerOlympicGuessInfo): OlympicGuessAllData
        {
            var loc8=null;
            var loc9=null;
            var loc10=0;
            var loc11=0;
            var loc12=0;
            var loc13=0;
            var loc1=new OlympicGuessAllData();
            var loc2=arg1.myType1;
            var loc3=arg1.type1Result;
            var loc4=this.getTodayNum();
            var loc5=[];
            var loc6=0;
            var loc7=0;
            var loc14=0;
            var loc15=loc3;
            for (loc8 in loc15) 
            {
                loc9 = new OlympicGuessData();
                loc10 = parseInt(loc8);
                loc11 = int(loc3[loc8]);
                loc12 = this.getAnswerByGoldNum(loc11);
                if ((loc13 = int(loc2[loc8])) == 0) 
                {
                    loc13 = -1;
                }
                loc9.answer = this.getAnswerStr(loc12);
                loc9.date = this.getDateStr(loc10);
                loc9.dateNum = loc10;
                loc9.goldNum = loc11;
                loc9.status = this.getOlympicGuessStatus(loc4, loc10, loc12, loc13);
                loc9.myAnswer = this.getAnswerStr(loc13);
                loc5[(loc9.dateNum - 1)] = loc9;
                if (this.isLeagalAnswer(loc13)) 
                {
                    ++loc6;
                }
                if (!loc9.isRight()) 
                {
                    continue;
                }
                ++loc7;
            }
            loc1.dailyDatas = loc5;
            loc1.goingDays = loc4;
            loc1.myGuessDays = loc6;
            loc1.myTotalRightDays = loc7;
            loc1.myTotalGoldNumAnswer = arg1.myType3Int;
            loc1.totalGoldNumAnswer = arg1.type3ResultInt;
            if (loc4 > 12 || this.isLeagalAnswer(loc1.myTotalGoldNumAnswer)) 
            {
                loc1.canAnswerTotalGoldNum = false;
            }
            else 
            {
                loc1.canAnswerTotalGoldNum = true;
            }
            return loc1;
        }

        /* internal  */isDictionaryGotAKey(arg1: Map<any, any> /* flash.utils.Dictionary */): Boolean
        {
            var loc2=undefined;
            if (arg1 == null) 
            {
                return false;
            }
            var loc1=0;
            var loc3=0;
            var loc4=arg1;
            for (loc2 in loc4) 
            {
                ++loc1;
            }
            return loc1 > 0;
        }

        /* internal  */getOlympicGuessStatus(arg1: int, arg2: int, arg3: int, arg4: int): string
        {
            if (this.isLeagalAnswer(arg4)) 
            {
                if (arg1 + 1 > arg2 && this.isLeagalAnswer(arg3)) 
                {
                    return OlympicGuessData.Status_Done;
                }
                if ((arg1 + 1 == arg2 || arg1 == arg2 || (arg1 - 1) == arg2) && !this.isLeagalAnswer(arg3)) 
                {
                    return OlympicGuessData.Status_Waitting;
                }
                return OlympicGuessData.Status_NotOpened;
            }
            else 
            {
                if (arg1 + 1 > arg2) 
                {
                    return OlympicGuessData.Status_Miss;
                }
                if (arg1 + 1 == arg2) 
                {
                    return OlympicGuessData.Status_Guessing;
                }
                if (arg1 + 1 < arg2) 
                {
                    return OlympicGuessData.Status_NotOpened;
                }
            }
            return OlympicGuessData.Status_NotOpened;
        }

        /* internal  */getAnswerStr(arg1: int): string
        {
            if (arg1 < 1 || arg1 >= this.AnswerLabels.length) 
            {
                return "未";
            }
            return this.AnswerLabels[arg1];
        }

        /* internal  */getAnswerByGoldNum(arg1: int): int
        {
            if (arg1 >= 10) 
            {
                return 4;
            }
            if (arg1 >= 7) 
            {
                return 3;
            }
            if (arg1 >= 4) 
            {
                return 2;
            }
            if (arg1 >= 0) 
            {
                return 1;
            }
            return -1;
        }

        /* internal  */isLeagalAnswer(arg1: int): Boolean
        {
            if (arg1 <= 0) 
            {
                return false;
            }
            if (arg1 > 4) 
            {
                return false;
            }
            return true;
        }

        /* internal  */getNotOpendData(arg1: int): OlympicGuessData
        {
            var loc1=new OlympicGuessData();
            loc1.answer = "";
            loc1.myAnswer = "";
            loc1.dateNum = arg1;
            loc1.date = this.getDateStr(arg1);
            loc1.status = OlympicGuessData.Status_NotOpened;
            return loc1;
        }

        /* internal  */getDateStr(arg1: int): string
        {
            if (arg1 <= 0 || arg1 > 16) 
            {
                return "";
            }
            return Language.getString((80019 + arg1 - 1));
        }

        /* internal  */getTodayNum(): int
        {
            var loc1=Cache.instance.active.getActiveByCode(EActiveType._EActiveTypeOlympicGuess).startDt;
            var loc2=this.getDays(loc1, ClockManager.instance.nowDate);
            if (loc2 < 0) 
            {
                return 0;
            }
            return loc2;
        }

        /* internal  */getDays(arg1: Date, arg2: Date): int
        {
            var loc1=arg1.fullYear;
            var loc2=arg1.month;
            var loc3=arg1.date;
            var loc4=arg2.fullYear;
            var loc5=arg2.month;
            var loc6=arg2.date;
            if (loc1 != loc4) 
            {
                return 10000;
            }
            if (loc2 < 6 || loc2 > 7) 
            {
                return 10000;
            }
            if (loc5 < 6 || loc5 > 7) 
            {
                return 10000;
            }
            if (loc2 < loc5) 
            {
                return 31 - loc3 + loc6;
            }
            if (loc2 == loc5) 
            {
                return loc6 - loc3;
            }
            return -10000;
        }

        /* internal */ /* const */AnswerLabels: Array<any>=["", "A", "B", "C", "D", "E"];
    }
